﻿// ===============================================================================
// Project Name        :    Gfw.BLL.Basic.User
// Project Description :    
// ===============================================================================
// Class Name          :    UserLogic
// Namespace:          :    Gfw.BLL.Basic.User
// Class Version       :    v1.0.0.0
// Class Description   :    
// CLR Version:        :    4.0.30319.17626
//Author               :    lif
// Machine             :    ADICO-PC
// Create Time         :    2012/7/1 9:49:29
// Update Time         :    2012/7/1 9:49:29
// ===============================================================================
// Copyright © lif 2012 . All rights reserved.
// ===============================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gfw.BLL.Basic.Account;
using Gfw.BLL.Basic.Stock;
using Gfw.Infrastructure.Account;
using Gfw.Infrastructure.ExceptionImpl;
using Gfw.Infrastructure.User;
using Gfw.Models.Account;
using Gfw.Models.Admin;
using Gfw.Repositories.Account;
using Gfw.Repositories.Admin;
using Gfw.Repository;
using Gfw.Web.Models.Account;
using Gfw.Web.Models.Genealogy;
using Gfw.Web.Models.User;

namespace Gfw.BLL.Basic.User
{
    public class UserLogic
    {
        #region Const Fields

        private const string DEFAULTPWD2 = "123";

        #endregion

        #region 基本操作

        /// <summary>
        /// 根据用户ID,获取用户信息
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static UsrUser GerUserInfo(string userId)
        {
            var repository = new UsrUserRepository();
            return repository.Get(userId);
        }

        /// <summary>
        /// 根据用户ID获取用户财务信息表
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public static UserFinanceModel GetUserFinanceByUserID(string userID)
        {
            var financeRespository = new UsrUserFinanceRepository();
            UsrUserfinance userFinance = financeRespository.GetUserFinanceByUserID(userID);

            if (userFinance != null)
            {
                UserFinanceModel financeInfo = new UserFinanceModel()
                {
                    UserID = userID,
                    BankName = userFinance.BankName,
                    BankCardNo = userFinance.BankCardNo,
                    BankAddress = userFinance.BankAddress,
                    BankUserName = userFinance.BankUserName,
                    Alipay = userFinance.Alipay,
                    TenPay = userFinance.TenPay,
                };

                return financeInfo;
            }
            else
                return null;
        }

        /// <summary>
        /// 获取用户绑定信息
        /// </summary>
        /// <param name="loginName">用户名</param>
        /// <returns></returns>
        public static UserBindingInfoModel GetUserBindingInfo(string loginName)
        {
            var userRepository = new UsrUserRepository();
            UsrUser userInfo = userRepository.GetUserByLoginName(loginName);

            if (userInfo != null && !string.IsNullOrEmpty(userInfo.Id))
            {
                UserBindingInfoModel userBindingInfo = new UserBindingInfoModel()
                {
                    UserID = userInfo.Id,
                    LoginName = userInfo.LoginName,
                    IDCard = userInfo.IdCard,
                    IsLock = userInfo.IsLock == 1 ? true : false,
                    LockDate = userInfo.LockDate.ToString(),
                    LockReason = userInfo.LockReason,
                };

                var financeRespository = new UsrUserFinanceRepository();
                UsrUserfinance userFinance = financeRespository.GetUserFinanceByUserID(userInfo.Id);

                if (userFinance != null)
                {
                    userBindingInfo.BankName = userFinance.BankName;
                    userBindingInfo.BankCardNo = userFinance.BankCardNo;
                    userBindingInfo.BankAddress = userFinance.BankAddress;
                    userBindingInfo.BankUserName = userFinance.BankUserName;
                    userBindingInfo.Alipay = userFinance.Alipay;
                    userBindingInfo.Tenpay = userFinance.TenPay;
                }

                return userBindingInfo;
            }
            else
                return null;
        }

        /// <summary>
        /// 获取用户基本信息
        /// </summary>
        /// <param name="loginName">用户名</param>
        /// <returns></returns>
        public static UserBasicInfoModel GetUserBasicInfo(string loginName)
        {
            var repository = new UsrUserRepository();
            UsrUser userInfo = repository.GetUserByLoginName(loginName);

            if (userInfo != null)
            {
                UserBasicInfoModel userBasicInfo = new UserBasicInfoModel()
                {
                    LoginName = userInfo.LoginName,
                    Address = userInfo.Address,
                    Email = userInfo.Email,
                    Name = userInfo.Name,
                    QQ = userInfo.Qq,
                    Tel = userInfo.Tel,
                };

                return userBasicInfo;
            }
            else
                return null;
        }

        /// <summary>
        /// 统计左右孩子总计
        /// </summary>
        /// <param name="recommenderID">推荐人ID</param>
        /// <param name="recommendCode">推荐人Code</param>
        /// <param name="leftChildrenCount">左总计</param>
        /// <param name="rightChildrenCount">右总计</param>
        public static void GetRecommendMembersCount(string recommenderID, string recommenderCode, out long leftChildrenCount, out long rightChildrenCount)
        {
            var repository = new UsrUserRepository();
            repository.GetRecommendMembersCount(recommenderID, recommenderCode, out leftChildrenCount, out rightChildrenCount);
        }

        /// <summary>
        /// 获取该会员所有被推荐的会员
        /// </summary>
        /// <param name="recommenderID">推荐人ID</param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalSize"></param>
        /// <returns></returns>
        public static IList<UserRecommendMemberModel> GetUserRecommendMembersInfo(string recommenderID, int pageIndex, int pageSize, out int totalSize)
        {
            // 获取推荐人 Code，用于判断区域
            string defaultRecommenderCode = string.Empty;
            UsrUser defaultRecommender = GerUserInfo(recommenderID);
            if (defaultRecommender != null)
            {
                defaultRecommenderCode = defaultRecommender.Code;
            }


            // 获取被推荐人
            var repository = new UsrUserRepository();
            IList<UsrUser> userInfoList = repository.GetUserRecommendMembersInfo(recommenderID, pageIndex, pageSize, out totalSize);

            IList<UserRecommendMemberModel> memberModelList = new List<UserRecommendMemberModel>();
            if (userInfoList != null && userInfoList.Count() > 0)
            {
                foreach (UsrUser user in userInfoList)
                {
                    UserRecommendMemberModel userRecommendMemberInfo = new UserRecommendMemberModel()
                    {
                        // 列表中只显示特殊字段
                        UserID = user.Id,
                        LoginName = user.LoginName,
                        //ActivationDate = user.ActivationDate.ToString(),
                        //Address = user.Address,
                        Code = user.Code,
                        //Email = user.Email,
                        //IsLock = user.IsLock == 1 ? true : false,
                        //LockDate = user.LockDate.ToString(),
                        //LockReason = user.LockReason,
                        Name = user.Name,
                        QQ = user.Qq,
                        RegistrationDate = user.RegistrationDate.ToString(),
                        Tel = user.Tel,
                        //UserIndex = user.UserIndex,
                        RecommenderCode = defaultRecommenderCode,
                    };

                    if (!string.IsNullOrEmpty(defaultRecommenderCode) && userRecommendMemberInfo.Code != null &&
                        userRecommendMemberInfo.Code.StartsWith(defaultRecommenderCode) &&
                        userRecommendMemberInfo.Code.Length > defaultRecommenderCode.Length)
                    {
                        if (userRecommendMemberInfo.Code.StartsWith(defaultRecommenderCode + "0"))
                            userRecommendMemberInfo.ChildArea = "左区";
                        else if (userRecommendMemberInfo.Code.StartsWith(defaultRecommenderCode + "1"))
                            userRecommendMemberInfo.ChildArea = "右区";
                        else
                            userRecommendMemberInfo.ChildArea = string.Empty;
                    }

                    memberModelList.Add(userRecommendMemberInfo);
                }
            }

            return memberModelList;
        }

        /// <summary>
        /// 获取被推荐会员详情
        /// </summary>
        /// <param name="recommenderID">推荐人ID</param>
        /// <param name="recommenderCode">推荐人Code</param>
        /// <returns></returns>
        public static UserRecommendMemberModel GetUserRecommendMemberInfoByUserID(string recommenderID, string recommenderCode)
        {
            // 获取被推荐人信息
            string defaultRecommenderCode = recommenderCode;
            UsrUser userInfo = GerUserInfo(recommenderID);

            if (userInfo != null)
            {
                UserRecommendMemberModel userRecommendMemberInfo = new UserRecommendMemberModel()
                {
                    UserID = userInfo.Id,
                    LoginName = userInfo.LoginName,
                    ActivationDate = userInfo.ActivationDate.ToString(),
                    Address = userInfo.Address,
                    Code = userInfo.Code,
                    Email = userInfo.Email,
                    IsLock = userInfo.IsLock == 1 ? true : false,
                    LockDate = userInfo.LockDate.ToString(),
                    LockReason = userInfo.LockReason,
                    Name = userInfo.Name,
                    QQ = userInfo.Qq,
                    RegistrationDate = userInfo.RegistrationDate.ToString(),
                    Tel = userInfo.Tel,
                    UserIndex = userInfo.UserIndex,
                };

                if (!string.IsNullOrEmpty(defaultRecommenderCode) && userRecommendMemberInfo.Code != null &&
                        userRecommendMemberInfo.Code.StartsWith(defaultRecommenderCode) &&
                        userRecommendMemberInfo.Code.Length > defaultRecommenderCode.Length)
                {
                    if (userRecommendMemberInfo.Code.StartsWith(defaultRecommenderCode + "0"))
                        userRecommendMemberInfo.ChildArea = "左区";
                    else if (userRecommendMemberInfo.Code.StartsWith(defaultRecommenderCode + "1"))
                        userRecommendMemberInfo.ChildArea = "右区";
                    else
                        userRecommendMemberInfo.ChildArea = string.Empty;
                }

                return userRecommendMemberInfo;
            }
            else
                return null;
        }

        /// <summary>
        /// 获取用户密保问题
        /// </summary>
        /// <param name="loginName"></param>
        /// <returns></returns>
        public static UserSecurityQuestionModel GetSecurityQuestions(string loginName)
        {
            var repository = new UsrUserRepository();
            UsrUser userInfo = repository.GetUserByLoginName(loginName);

            if (userInfo != null)
            {
                UserSecurityQuestionModel securityQuestion = new UserSecurityQuestionModel()
                {
                    LoginName = userInfo.LoginName,
                    Question1 = userInfo.Question1,
                    Answer1 = userInfo.Answer1,
                    Question2 = userInfo.Question2,
                    Answer2 = userInfo.Answer2,
                    Question3 = userInfo.Question3,
                    Answer3 = userInfo.Answer3,
                };

                return securityQuestion;
            }
            else
                return null;
        }

        /// <summary>
        /// 根据code获取登录名
        /// </summary>
        /// <param name="code">code代码</param>
        /// <returns></returns>
        public static string GerLoginName(string code)
        {
            UsrUserRepository repository = new UsrUserRepository();
            var user = repository.GetUserByCode(code);
            return user.LoginName;
        }

        /// <summary>
        /// 根据用户登录名获取用户ID
        /// </summary>
        /// <param name="loginName">用户登录名</param>
        /// <returns>用户ID</returns>
        public static string GetUserIDByLoginName(string loginName)
        {
            UsrUserRepository repository = new UsrUserRepository();
            var user = repository.GetUserByLoginName(loginName);
            if (user == null)
                return string.Empty;

            return user.Id;
        }

        /// <summary>
        /// 根据用户ID获取用户登录名
        /// </summary>
        /// <param name="userID">用户ID</param>
        /// <returns>用户登录名</returns>
        public static string GetLoginNameByUserID(string userID)
        {
            UsrUserRepository repository = new UsrUserRepository();
            var user = repository.Get(userID);
            if (user == null)
                return string.Empty;

            return user.LoginName;
        }

        /// <summary>
        /// 判断是否第一次设置二级密码
        /// </summary>
        /// <param name="loginName"></param>
        /// <returns></returns>
        public static bool IsFirstSetSecondPassword(string loginName)
        {
            var repository = new UsrUserRepository();
            UsrUser userInfo = repository.GetUserByLoginName(loginName);

            return string.IsNullOrEmpty(userInfo.SecondPassword);
        }


        //////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// 根据用户ID获取用户详细信息
        /// </summary>
        /// <param name="userID">用户ID</param>
        /// <returns></returns>
        public static UserFullDetailModel GetUserFullDetailInfoByUserID(string userID)
        {
            UserFullDetailModel userDetailModel = new UserFullDetailModel();

            // 以下是：用户基本信息
            UsrUser user = GerUserInfo(userID);
            if (user != null)
            {
                userDetailModel.UserDetailInfo = user.CopyTo<UserDetailInfoModel>();
                userDetailModel.UserDetailInfo.IsLock = user.IsLock == 1 ? "是" : "否";
                long leftCount, rightCount;
                GetRecommendMembersCount(user.Id, user.Code, out leftCount, out rightCount);
                userDetailModel.UserDetailInfo.LeftChildrenCount = leftCount;
                userDetailModel.UserDetailInfo.RightChildrenCount = rightCount;
            }
            

            // 以下是：用户财务信息
            UserFinanceModel finance = GetUserFinanceByUserID(userID);
            if (finance != null)
            {
                userDetailModel.UserFinanceInfo = finance.CopyTo<UserFinanceModel>();
            }


            // 以下是：用户账户信息
            UserAccountModel account = UserAccountLogic.GetUserAccount(userID);
            if (account != null)
            {
                userDetailModel.UserAccountInfo = account.CopyTo<UserAccountModel>();
            }

            return userDetailModel;
        }

        /// <summary>
        /// 根据用户ID获取用户详细基本信息+提现申请信息
        /// </summary>
        /// <param name="userID">用户ID</param>
        /// <param name="applyDate">提现申请时间</param>
        /// <returns></returns>
        public static CashDetailModel GetUserCashDetailInfoByUserID(string userID, DateTime applyDate)
        {
            CashDetailModel cashDetailModel = new CashDetailModel();

            // 以下是：用户详细信息
            cashDetailModel.UserFullDetailInfo = GetUserFullDetailInfoByUserID(userID);

            // 以下是：用户提现申请信息
            ActCompanyCashRepository cashRepository = new ActCompanyCashRepository();
            ActCompanyCash cash = cashRepository.GetCashByUserIDAndApplyDate(userID, applyDate);
            cashDetailModel.UserCashApplyInfo = cash.CopyTo<CashQueryCmpModel>();
            cashDetailModel.UserCashApplyInfo.LoginName = cashDetailModel.UserFullDetailInfo.UserDetailInfo.LoginName;
            cashDetailModel.UserCashApplyInfo.UserID = cashDetailModel.UserFullDetailInfo.UserDetailInfo.Id;
            switch (cash.Status)
            {
                case (int)CashStatusEnum.Cancel:
                    cashDetailModel.UserCashApplyInfo.Status = "审核不通过";
                    break;
                case (int)CashStatusEnum.Wait:
                    cashDetailModel.UserCashApplyInfo.Status = "审核中";
                    break;
                case (int)CashStatusEnum.Pass:
                    cashDetailModel.UserCashApplyInfo.Status = "审核通过";
                    break;

                default:
                    cashDetailModel.UserCashApplyInfo.Status = string.Empty;
                    break;
            }

            return cashDetailModel;
        }


        //////////////////////////////////////////////////////////////////////////


        /// <summary>
        /// 修改用户登录密码
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool ChangeLoginPassword(UserLoginPasswordModel model)
        {
            if (model == null)
                return false;

            UsrUserRepository _userRepository = new UsrUserRepository();
            return _userRepository.ChangePassword(model.LoginName,
                EncryptAlgorithmHelper.Encrypt(model.OldPassword, model.LoginName),
                EncryptAlgorithmHelper.Encrypt(model.NewPassword, model.LoginName));
        }

        /// <summary>
        /// 修改用户二级密码
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool ChangeSecondPassword(UserSecondPasswordModel model)
        {
            if (model == null)
                return false;

            UsrUserRepository _userRepository = new UsrUserRepository();
            return _userRepository.ChangeSecondPassword(model.LoginName,
                EncryptAlgorithmHelper.Encrypt(model.Password, model.LoginName),
                EncryptAlgorithmHelper.Encrypt(model.OldSecondPassword, model.LoginName),
                EncryptAlgorithmHelper.Encrypt(model.NewSecondPassword, model.LoginName));
        }

        /// <summary>
        /// 修改会员基本信息
        /// </summary>
        /// <param name="model"></param>
        public static void EditUserBasicInfo(UserBasicInfoModel model)
        {
            if (model == null)
                return;

            UsrUserRepository _userRepository = new UsrUserRepository();
            UsrUser _oneUser = _userRepository.GetUserByLoginName(model.LoginName);

            if (_oneUser != null)
            {
                _oneUser.Address = model.Address;
                _oneUser.Email = model.Email;
                _oneUser.Name = model.Name;
                _oneUser.Qq = model.QQ;
                _oneUser.Tel = model.Tel;

                _userRepository.Update(_oneUser);
            }
        }

        /// <summary>
        /// 修改会员绑定信息
        /// <para>这里只修改：身份证号、是否锁定、锁定时间、锁定原因</para>
        /// </summary>
        /// <param name="model"></param>
        public static void EditUserBindingInfo(UserBindingInfoModel model)
        {
            if (model == null)
                return;

            UsrUserRepository _userRepository = new UsrUserRepository();
            UsrUser _oneUser = _userRepository.GetUserByLoginName(model.LoginName);

            if (_oneUser != null)
            {
                _oneUser.IdCard = model.IDCard;
                _oneUser.IsLock = model.IsLock ? 1 : 0;

                if (model.IsLock) // 用条件表达式有问题？
                    _oneUser.LockDate = DateTime.Now;
                else
                    _oneUser.LockDate = null;

                _oneUser.LockReason = model.LockReason;

                _userRepository.Update(_oneUser);
            }
        }

        /// <summary>
        /// 修改会员绑定信息
        /// <para>这里只修改：用户财务信息等（如：银行卡号等）</para>
        /// </summary>
        /// <param name="model"></param>
        public static void EditUserFinanceInfo(UserBindingInfoModel model)
        {
            if (model == null)
                return;

            UsrUserRepository _userRepository = new UsrUserRepository();
            UsrUser _oneUser = _userRepository.GetUserByLoginName(model.LoginName);

            if (_oneUser != null)
            {
                UsrUserFinanceRepository _financeRepository = new UsrUserFinanceRepository();
                UsrUserfinance _userFinance = _financeRepository.GetUserFinanceByUserID(_oneUser.Id);

                if (_userFinance != null)
                {
                    _userFinance.BankAddress = model.BankAddress;
                    _userFinance.BankCardNo = model.BankCardNo;
                    _userFinance.BankName = model.BankName;
                    _userFinance.BankUserName = model.BankUserName;
                    _userFinance.Alipay = model.Alipay;
                    _userFinance.TenPay = model.Tenpay;

                    _financeRepository.Update(_userFinance);
                }
                else
                {
                    UsrUserfinance _addFinance = new UsrUserfinance()
                    {
                        Id = Guid.NewGuid().ToString(),
                        Userid = _oneUser,
                        BankName = model.BankName,
                        BankCardNo = model.BankCardNo,
                        BankUserName = model.BankUserName,
                        BankAddress = model.BankAddress,
                        Alipay = model.Alipay,
                        TenPay = model.Tenpay,
                    };

                    _financeRepository.Save(_addFinance);
                }
            }
        }

        /// <summary>
        /// 修改密保问题
        /// </summary>
        /// <param name="model"></param>
        public static void EditSecurityQuestion(UserSecurityQuestionModel model)
        {
            if (model == null)
                return;

            UsrUserRepository _userRepository = new UsrUserRepository();
            UsrUser _oneUser = _userRepository.GetUserByLoginName(model.LoginName);

            if (_oneUser != null)
            {
                _oneUser.Question1 = model.Question1;
                _oneUser.Answer1 = model.Answer1;
                _oneUser.Question2 = model.Question2;
                _oneUser.Answer2 = model.Answer2;
                _oneUser.Question3 = model.Question3;
                _oneUser.Answer3 = model.Answer3;

                _userRepository.Update(_oneUser);
            }
        }

        /// <summary>
        /// 重置登录密码
        /// </summary>
        /// <param name="loginName"></param>
        /// <returns></returns>
        public static bool ResetLoginPassword(string loginName)
        {
            UsrUserRepository _userRepository = new UsrUserRepository();
            return _userRepository.ResetLoginPassword(loginName);
        }

        /// <summary>
        /// 重置二级密码
        /// </summary>
        /// <param name="loginName"></param>
        /// <returns></returns>
        public static bool ResetSecondPassword(string loginName)
        {
            UsrUserRepository _userRepository = new UsrUserRepository();
            return _userRepository.ResetSecondPassword(loginName);
        }

        /// <summary>
        /// 重置密保问题
        /// </summary>
        /// <param name="loginName"></param>
        /// <returns></returns>
        public static bool ResetSecurityQuestion(string loginName)
        {
            UsrUserRepository _userRepository = new UsrUserRepository();
            return _userRepository.ResetSecurityQuestion(loginName);
        }

        #endregion

        #region 用户注册

        public static UserRegisterModel CheckParent(string createUserCode, long userCodeNumber)
        {
            string code = Convert.ToString(userCodeNumber, 2);
            if (!code.StartsWith(createUserCode))
                throw new GfwVerifyException("你不能创建自己节点以外的用户！");

            long parentNumber =
               Convert.ToInt64(code.Substring(0, code.Length - 1), 2);
            UsrUserRepository repository = new UsrUserRepository();
            var user = repository.GetUserByCodeNumber(parentNumber);

            if (user == null)
                return null;

            if (user.IsActivation == (int)UserStatusEnum.NotActive)
                throw new GfwVerifyException("父节点未激活，你不能添加子节点！");

            return user.CopyTo<UserRegisterModel>();


        }


        public static bool Register(UserRegisterModel registerModel)
        {
            try
            {
                _Register(registerModel);
                return true;
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }

        /// <summary>
        /// 创建用户，并同时创建用户帐户信息
        /// </summary>
        /// <param name="registerModel"></param>
        public static void _Register(UserRegisterModel registerModel)
        {
            if(CheckUserLoginNameKeyWord(registerModel.LoginName))
                throw new GfwException("登录名为系统关键字，不可使用。");

            var repository = new UsrUserRepository();
            //唯一性测试
            if (repository.UniqueCheck(registerModel.LoginName, registerModel.Parentid, registerModel.ParentArea))
            {
                UsrUser user = new UsrUser()
                {
                    Id = Guid.NewGuid().ToString(),
                    LoginName = registerModel.LoginName,
                    Password = EncryptAlgorithmHelper.Encrypt(registerModel.Password, registerModel.LoginName),
                    SecondPassword = EncryptAlgorithmHelper.Encrypt(DEFAULTPWD2, registerModel.LoginName),
                    Parentid = registerModel.Parentid,
                    ParentArea = registerModel.ParentArea,
                    ParentName = registerModel.ParentName,
                    Code = registerModel.Code,
                    CodeNumber = registerModel.CodeNumber,
                    Recommender = registerModel.Recommender,
                    RecommenderName = registerModel.RecommenderName,
                    RegistrationDate = DateTime.Now,
                    IsActivation = (int)UserStatusEnum.NotActive,
                };
                UnitOfWork work = new UnitOfWork();
                repository.Save(user, work);
                UserAccountLogic.CreateNewUserAccount(user.Id, work);
                UsAccountLogic.NewUserAccount(user.Id, work);
                work.Commit();
            }
            else
            {
                throw new GfwException("登录名已经被注册或区位已经被占用。");
            }
        }

        /// <summary>
        /// 检测用户注册名是否是禁用的关键字
        /// </summary>
        /// <param name="loginName">登录名</param>
        /// <returns></returns>
        private static bool CheckUserLoginNameKeyWord(string loginName)
        {
            foreach (string key in new UserLoginNameKeyWordListModel().ToList<string>())
            {
                if (key.Equals(loginName.ToLower()))
                    return true;
            }

            return false;
        }

        /// <summary>
        /// 检查用户身份证号唯一性
        /// </summary>
        /// <param name="loginName">用户登录名</param>
        /// <param name="idCard">身份证号</param>
        /// <returns></returns>
        public static bool CheckUserIDCard(string loginName, string idCard)
        {
            var repository = new UsrUserRepository();
            return repository.UniqueCheckIDCard(loginName, idCard);
        }

        #endregion

        #region 二级密码核对

        public static bool CheckSecondSecurity(string loginName, string password2)
        {
            UsrUserRepository _userRepository = new UsrUserRepository();
            return _userRepository.SecondValidate(loginName, password2);
        }

        #endregion
    }
}
